<template>
  <div class="app-header-sticky" :class="{show: top > 78}">
    <div class="container" v-if='top > 78'>
      <!-- 左侧图标 -->
      <RouterLink class="logo" to="/" />
      <!-- 中间的分类导航菜单 -->
      <TopHeaderCommon />
      <!-- 右侧按钮 -->
      <div class="right">
        <RouterLink to="/">品牌</RouterLink>
        <RouterLink to="/">专题</RouterLink>
      </div>
    </div>
  </div>
</template>

<script>
import TopHeaderCommon from '@/components/top-header-common.vue'
// import { ref } from 'vue'
import { useWindowScroll } from '@vueuse/core'

export default {
  name: 'AppHeaderSticky',
  components: { TopHeaderCommon },
  setup () {
    // const top = ref(0)
    // 监听窗口的滚动距离
    // window.onscroll = () => {
    //   top.value = document.documentElement.scrollTop
    // }

    // 对象解构赋值之后可以通过【:别名】的方式起一个新的名字
    const { y: top } = useWindowScroll()
    return { top }
  }
}
</script>

<style scoped lang='less'>
.app-header-sticky {
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
  // 此处为关键样式!!!
  // 默认情况下完全把自己移动到上面
  transform: translateY(-100%);
  // 完全透明
  opacity: 0;
  // 显示出来的类名
  &.show {
    transition: all 0.3s linear;
    transform: none;
    opacity: 1;
  }
  .container {
    display: flex;
    align-items: center;
  }
  .logo {
    width: 200px;
    height: 80px;
    background: url('~@/assets/images/logo.png') no-repeat right 2px;
    background-size: 160px auto;
  }
  .right {
    width: 220px;
    display: flex;
    text-align: center;
    padding-left: 40px;
    border-left: 2px solid @xtxColor;
    a {
      width: 38px;
      margin-right: 40px;
      font-size: 16px;
      line-height: 1;
      &:hover {
        color: @xtxColor;
      }
    }
  }
}
</style>
